****************************************************************************
**		Authors: 	Or Tuttnauer & Liran Harsgor
**		Purpose: 	Produce Figure 2 in Kedar, Harsgor & Tuttnauer (JOP)  
**		input:		KHT_countrylevel.dta, KHT_districtlevel.dta
*****************************************************************************

log using "figure 2.log", replace

set more off

/*Figure 2a*/
use "KHT_countrylevel.dta", clear

scatter sr meddm if dpr==1, ///
                ysca(alt) xsca(alt)  ///
                xlabel(, gmax nogrid) mlabel(cyear) mlabsize(vsmall) msize(vsmall) /// 
				ylabel(1 2 3 4 5 6, nogrid) ///
				xtitle("") ///
				ytitle("") yscale(range(1 6)) ///
				saving(scat, replace)
				
		twoway histogram sr if dpr==1, ///
                freq ///
				width(0.2) ///
				xsca(alt reverse) yscale(range(1 6)) horiz  ///
				ylabel(,nogrid) ///
				xtitle("") ///
				ytitle("") ///
				saving(himr, replace) ///
				fxsize(30)
				
        twoway histogram meddm if dpr==1, ///
                freq ///
				width(1) ///
				ysca(alt reverse) ///
                ylabel(,nogrid) ///
                xtitle("") ///
				ytitle("") ///
				saving(hmeddm, replace) ///
				fysize(30)

graph combine himr.gph scat.gph hmeddm.gph, ///
                hole(3) imargin(0 0 0 0) graphregion(margin(l=22 r=22)) ///
				scheme(s1mono) ///
			 saving("figure 2a", replace)

pwcorr(sddm meddm)  if dpr==1, obs sig


/*Figure 2b*/
use "KHT_districtlevel.dta", clear  

** Portugal **
levelsof meddm if cyear=="PRT09", local(meddm) clean
	twoway hist dm if cyear=="PRT09", discrete frequency fintensity(inten0) ///
	title("Portugal") xlabel(0(10)70) ///
	lcolor(gs10) lwidth(thin) legend(off) ///
	|| scatteri 0 `meddm' 3.2 `meddm', recast(line) lcolor(black) lwidth(medthick) ///
	graphregion(fcolor(white)) yla(,nogrid) ///
	xtitle("District magnitude", size(3)) ytitle("Frequency", size(3))
	graph save "por_hist", replace
	
** Brazil **
levelsof meddm if cyear=="BRA10", local(meddm) clean
	twoway hist dm if cyear=="BRA10", discrete frequency fintensity(inten0) ///
	title("Brazil") xlabel(0(10)70) ///
	lcolor(gs10) lwidth(thin) legend(off) ///
	|| scatteri 0 `meddm' 12 `meddm', recast(line) lcolor(black) lwidth(medthick) ///
	graphregion(fcolor(white)) yla(,nogrid) ///
	ylabel(0(2)12) xtitle("District magnitude", size(3)) ytitle("Frequency", size(3))
	graph save "brz_hist", replace
	
** Malta **
levelsof meddm if cyear=="MLT08", local(meddm) clean
	twoway hist dm if cyear=="MLT08", discrete frequency fintensity(inten0) ///
	title("Malta") xlabel(0(10)70) ///
	lcolor(gs10) lwidth(thin) legend(off) ///
	|| scatteri 0 `meddm' 15 `meddm', recast(line) lcolor(black) lwidth(medthick) ///
	graphregion(fcolor(white)) yla(,nogrid) ///
	ylabel(0(5)15) xtitle("District magnitude", size(3)) ytitle("Frequency", size(3))
	graph save "mlt_hist", replace

** Iceland **
levelsof meddm if cyear=="ISL09", local(meddm) clean
	twoway hist dm if cyear=="ISL09", discrete frequency fintensity(inten0) ///
	title("Iceland") xlabel(0(10)70) ///
	lcolor(gs10) lwidth(thin) legend(off) ///
	|| scatteri 0 `meddm' 2.2 `meddm', recast(line) lcolor(black) lwidth(medthick) ///
	graphregion(fcolor(white)) yla(,nogrid) ///
	ylabel(0 1 2) xtitle("District magnitude", size(3)) ytitle("Frequency", size(3))
	graph save "icl_hist", replace
	
graph combine "por_hist" "mlt_hist" "brz_hist" "icl_hist", ///
col(4) scheme(s2mono) graphregion(fcolor(white)) xsize(11) ysize(4)
graph save "figure 2b", replace

log close
